#include "main.h"

Moon::Moon(void)
{
	
}

Moon::Moon(double x,double y,double z,double r,double speedm)
{	
	//x,y and x values for the translation matrix
	_x=x;  
	_y=y;
	_z=z;
	//set the rotation speed for the moon
	_speed=speedm;
	//radomize orbit position
	_spin=rand()%360;
	//set the radius
	_radius=r;
	//set the texture path
	path="textures/moon.bmp";
}

Moon::~Moon(void)
{
}
//Initialize texture
void Moon::init()
{
  glLoadIdentity();
  glOrtho(-1.0, 1.0, -1.0, 1.0, -2.0, 2.0);
     
  moons = gluNewQuadric();
  gluQuadricTexture( moons, GL_TRUE);
  moonsTexture = LoadBitmap(path.c_str());
}

void Moon::spinm()
{
	//update rotation speed or angle
	_spin+=_speed;
	// spin for ever
	if(_spin>360.0)
	_spin=_spin-360.0;

}

void Moon::draw()
{
//enable the textures
glEnable ( GL_TEXTURE_2D );
//select texture to be applied
glBindTexture ( GL_TEXTURE_2D, moonsTexture);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
// Multiply the current matrix by a rotation matrix
glRotated((GLdouble) _spin, 0.0, 0.0, -1.0);
//set location of moons
glTranslated (_x, _y, _z);
//spin moon around self axis
glRotated((GLdouble) _spin*10, 0.0, 0.0, -1.0);
// Draw a sphere on the screen
gluSphere(moons,_radius,30,30);
//disable textures
glDisable (GL_TEXTURE_2D);
glPopMatrix();
}


